// 定义语句块
// 定义语句块下面对应的代码块
// 定义块
const path = require('path');
const staticImg = path.join(__dirname, 'static');
function SensorbitUnoBlocks(Blockly) {

    var base_color = "#179b73";
    var show_color = "#f59057";
    var color_do = "#FF0000";
    var color_sensor = "#28BFE6";

    var color_basic = '#00979D';
    var color_display = '#00979D';
    var color_music = '#00979D';
    var color_led = '#00979D';
    var color_wifi = '#00979D';
   
    var color_math = '#59C059';
    var color_list = '#E65722';
    var color_text = '#B8860B';
   
    var color_images = '#00979D';
    var color_pin = '#00979D';
    var color_serial = '#00979D';
    var color_control = '#FFAB19';
    var color_events = "#D2691E";

    //      当开机时
    Blockly.Blocks.microbitStart = {
        //        /**
        //         * Block for if-else.
        //         * @this Blockly.Block 'micro:bit主程序开始',
        //         */
               init: function () {
                   this.jsonInit({
                       type: 'microbitStart',
                       message0: '',
                       message1:  Blockly.Msg.MICROBIT_MAINSTART,
                       message2: '%1 ',
                        args0: [],
                        args1: [],
                        args2: [
                        {
                            type: 'input_statement',
                            name: 'SUBSTACK0'
                        }
                    ],
                       category: Blockly.Categories.event,
                       extensions: ['colours_sensorbit', 'scratch_extension']
                   });
               }
           };
           Blockly.ScratchBlocks.VerticalExtensions.MICROBIT = function() {
            this.setColour('#D2691E');
          };
          Blockly.Extensions.register('colours_sensorbit',Blockly.ScratchBlocks.VerticalExtensions.MICROBIT);
        
                // 无线循环
            Blockly.Blocks.microbitLoop = {
                init: function (){
                    this.setColour(color_events);
                    this.appendDummyInput("")
                        // .appendField('当开机时');
                        .appendField(Blockly.Msg.MICROBIT_LOOP);
                    // this.appendValueInput("serialprints1", String);
                    this.appendStatementInput('SUBSTACK0')
                        .appendField('');
                    // this.setPreviousStatement(false);
                    this.setNextStatement(false);
                    this.setOutputShape(5);
                    this.setTooltip('');
                }
            };
        
            //
            Blockly.Blocks.microbitButton = {
                init: function (){
                    this.setColour(color_events);
                    this.appendDummyInput("")
                        // .appendField('当开机时');
                        .appendField(Blockly.Msg.MICROBIT_WHENBUTTON)
                        .appendField(new Blockly.FieldDropdown([
                            ['A', "a"],
                            ['B', "b"],
                            ['A+B', "ab"],
                        ]), "buttonEvent")
                        .appendField(Blockly.Msg.MICROBIT_ISBUTTONEVENT);
                    // this.appendValueInput("serialprints1", String);
                    this.appendStatementInput('SUBSTACK0')
                        .appendField('');
                    // this.setPreviousStatement(false);
                    this.setNextStatement(false);
                    this.setOutputShape(5);
                    this.setTooltip('');
                }
            };
        
            //显示数字  Blockly.Msg.MICROBIT_TRIFFICLIGHTSRED
            Blockly.Blocks.displayShowNumber = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DISPLAYNUMBER)
                    this.appendValueInput("displayShowNumber", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //显示图像 
            Blockly.Blocks.displayShowImageView = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DISPLAYPICTURE)
                        .appendField(new Blockly.FieldDropdown([
                            ['HEART', "Image.HEART"],
                            ['HAPPY', "Image.HAPPY"],
                            ['SMILE', "Image.SMILE"],
                            ['SAD', "Image.SAD"],
                            ['CONFUSED', "Image.CONFUSED"],
                            ['ANGRY', "Image.ANGRY"],
                            ['ASLEEP', "Image.ASLEEP"],
                            ['SURPRISED', "Image.SURPRISED"],
                            ['MEH', "Image.MEH"],
                            ['YES', "Image.YES"],
                            ['NO', "Image.NO"],
                        ]), "image")
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 显示字符串
            Blockly.Blocks.displayShowString = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DISPLAYSHOW)
                    this.appendValueInput("displayShowString", String)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 暂停  millisecond
            Blockly.Blocks.pauseSleep = {
                init: function () {
                    this.setColour(color_control);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.SUSPEND)
                        this.appendValueInput("sleepTime", Number)
                        this.appendDummyInput("")
                        .appendField(Blockly.Msg.MILLISECOND)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 显示箭头
            Blockly.Blocks.displayShowArrow = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.SHOWARROW)
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.NORTH, "Image.ARROW_N"],
                            [Blockly.Msg.NORTHEAST, "Image.ARROW_EN"],
                            [Blockly.Msg.EAST, "Image.ARROW_E"],
                            [Blockly.Msg.SOUTHEAST, "Image.ARROW_SE"],
                            [Blockly.Msg.SOUTH, "Image.ARROW_S"],
                            [Blockly.Msg.SOUTHWEST, "Image.ARROW_SW"],
                            [Blockly.Msg.WEST, "Image.ARROW_W"],
                            [Blockly.Msg.NORTHWEST, "Image.ARROW_NW"],
                        ]), "displayShowArrow")
                    this.appendDummyInput("")
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //无限循环
            Blockly.Blocks.infiniteCycle = {
                init: function () {
                    this.setColour(color_basic);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.LOOP);
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //清空屏幕
            Blockly.Blocks.emptyScreen = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.CLEAR);
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
        
              //当按钮被按下时
              Blockly.Blocks.buttonPressed = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.KEY)
                        .appendField(new Blockly.FieldDropdown([
                            ['A', "A"],
                            ['B', "B"],
                            ['A+B', "A+B"],
                        ]), "Button")
                        .appendField(Blockly.Msg.ISPRESSED);
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //当改变主板状态
            Blockly.Blocks.stateChange = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.CURRENTMOTHERBOARD)
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.SHOCK, "shock"],
                            [Blockly.Msg.LOGOUP, "up"],
                            [Blockly.Msg.LOGODOWN, "down"],
                            [Blockly.Msg.SCREENUP, "screenup"],
                            [Blockly.Msg.SCREENDOWN, "screendown"],
                            [Blockly.Msg.LEFTTILT, "left"],
                            [Blockly.Msg.RIGHTTILT, "right"],
                            [Blockly.Msg.FREEFALL, "fall"],
                            ['3g', "3g"],
                            ['6g', "6g"],
                            ['8g', "8g"],
                        ]), "state");
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //当引脚被接通时
            Blockly.Blocks.pinTouched = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.WHENPIN)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "p0"],
                            ['p1', "p1"],
                            ['p2', "p2"],
                        ]), "Pin")
                        .appendField(Blockly.Msg.ISPRESSED);
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //当按钮被按下时
            Blockly.Blocks.buttonPressedTowState = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.KEY)
                        .appendField(new Blockly.FieldDropdown([
                            ['A', "A"],
                            ['B', "B"],
                            ['A+B', "A+B"],
                        ]), "Button")
                        .appendField(Blockly.Msg.ISPRESSED);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
                    this.setOutput(true, 'Boolean');
                    this.setTooltip('');
                }
            };
        
            //当引脚被接通
            Blockly.Blocks.pinPressedTowState = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.WHENPIN)
                        .appendField(new Blockly.FieldDropdown([
                            ['P0', "p0"],
                            ['P1', "p1"],
                            ['P2', "p2"],
                        ]), "PinState")
                        .appendField(Blockly.Msg.ISPRESSED);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
                    this.setOutput(true, 'Boolean');
                    this.setTooltip('');
                }
            };
        
        
        //加速度
        Blockly.Blocks.accelerationValue = {
            init: function () {
                this.setColour(color_display);
                this.appendDummyInput("")
                    .appendField(Blockly.Msg.ACCELERATEDSPEED)
                    .appendField(new Blockly.FieldDropdown([
                        ['x', "x"],
                        ['y', "y"],
                        ['z', "z"],
                    ]), "acceleration")
                this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                this.setOutput(true, 'String');
                this.setTooltip('');
            }
        };
        
        //亮度级别
        Blockly.Blocks.brightnessLevel = {
            init: function () {
                this.setColour(color_led);
                this.appendDummyInput("")
                    .appendField(Blockly.Msg.BRIGHTNESSLEVEL
                        )
                this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                this.setOutput(true, 'String');
                this.setTooltip('');
            }
        };
        
        //指针朝向
        Blockly.Blocks.pointerOrientation = {
            init: function () {
                this.setColour(color_display);
                this.appendDummyInput("")
                    .appendField(Blockly.Msg.POINTERFACING)
                this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                this.setOutput(true, 'String');
                this.setTooltip('');
            }
        };
        
        //温度
        Blockly.Blocks.temperaTure = {
            init: function () {
                this.setColour(color_display);
                this.appendDummyInput("")
                    .appendField(Blockly.Msg.TEMPERATURE)
                this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                this.setOutput(true, 'String');
                this.setTooltip('');
            }
        };
        
            //旋转方式
            Blockly.Blocks.rotationMode = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.ROTATE)
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.ROTATE1, "rotate"],
                            [Blockly.Msg.ROLL, "roll"],
                        ]), "rotation")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //磁力磁力（μT）
            Blockly.Blocks.magneticForce = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.MAGNETICFORCE)
                        .appendField(new Blockly.FieldDropdown([
                            ['x', "x"],
                            ['y', "y"],
                            ['z', "z"],
                            // [Blockly.Msg.STRENGTH, "strength"],
                        ]), "magnetic")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //运行时间
            Blockly.Blocks.runningTime = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.RUNTIME)
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                }
            };
        
            //校准指南针
            Blockly.Blocks.calibrateCompass = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.CALIBRATECOMPASS)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //当引脚被释放时
            Blockly.Blocks.pinPressedThreeState = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.WHENPIN)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "p0"],
                            ['p1', "p1"],
                            ['p2', "p2"],
                        ]), "State")
                        .appendField(Blockly.Msg.ISRELEASED);
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //音乐
            // 播放音调
            Blockly.Blocks.playTone = {
                init: function () {
                    this.setColour(color_music);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PLAYMELODYPIN)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p10', "pin10"],
                        ]), "playPin") 
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PLAYTONE)
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.LOWC, "131"],
                            [Blockly.Msg.LOWD, "147"],
                            [Blockly.Msg.LOWE, "165"],
                            [Blockly.Msg.LOWF, "175"],
                            [Blockly.Msg.LOWG, "196"],
                            [Blockly.Msg.LOWA, "220"],
                            [Blockly.Msg.LOWB, "247"],
                            [Blockly.Msg.MIDDLEC, "262"],
                            [Blockly.Msg.MIDDLED, "294"],
                            [Blockly.Msg.MIDDLEE, "330"],
                            [Blockly.Msg.MIDDLEF, "349"],
                            [Blockly.Msg.MIDDLEG, "392"],
                            [Blockly.Msg.MIDDLEA, "440"],
                            [Blockly.Msg.MIDDLEB, "494"],
                            [Blockly.Msg.HIGHC, "523"],
                            [Blockly.Msg.HIGHD, "587"],
                            [Blockly.Msg.HIGHE, "659"],
                            [Blockly.Msg.HIGHF, "698"],
                            [Blockly.Msg.HIGHG, "784"],
                            [Blockly.Msg.HIGHA, "880"],
                            [Blockly.Msg.HIGHB, "988"],
                        ]), "tone")
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.CONTINUED)
                        .appendField(new Blockly.FieldDropdown([
                            ['1', "1"],
                            ['1/2', "0.5"],
                            ['1/4', "0.25"],
                            ['1/8', "0.125"],
                            ['1/16', "0.0625"],
                            ['2', "2"],
                            ['4', "4"],
                        ]), "rhythm")
                        .appendField(Blockly.Msg.RHYTHM);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //播放铃声（Hz）
            Blockly.Blocks.playRingTone = {
                init: function () {
                    this.setColour(color_music);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PLAYMELODYPIN)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p10', "pin10"],
                        ]), "playPin") 
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PLAYRINGTONE)
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.LOWC, "131"],
                            [Blockly.Msg.LOWD, "147"],
                            [Blockly.Msg.LOWE, "165"],
                            [Blockly.Msg.LOWF, "175"],
                            [Blockly.Msg.LOWG, "196"],
                            [Blockly.Msg.LOWA, "220"],
                            [Blockly.Msg.LOWB, "247"],
                            [Blockly.Msg.MIDDLEC, "262"],
                            [Blockly.Msg.MIDDLED, "294"],
                            [Blockly.Msg.MIDDLEE, "330"],
                            [Blockly.Msg.MIDDLEF, "349"],
                            [Blockly.Msg.MIDDLEG, "392"],
                            [Blockly.Msg.MIDDLEA, "440"],
                            [Blockly.Msg.MIDDLEB, "494"],
                            [Blockly.Msg.HIGHC, "523"],
                            [Blockly.Msg.HIGHD, "587"],
                            [Blockly.Msg.HIGHE, "659"],
                            [Blockly.Msg.HIGHF, "698"],
                            [Blockly.Msg.HIGHG, "784"],
                            [Blockly.Msg.HIGHA, "880"],
                            [Blockly.Msg.HIGHB, "988"],
                        ]), "tone")
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //暂停播放（ms）
            Blockly.Blocks.pausePlayback = {
                init: function () {
                    this.setColour(color_music);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PAUSEPLAYBACK)
                        .appendField(new Blockly.FieldDropdown([
                            ['1', "1"],
                            ['1/2', "0.5"],
                            ['1/4', "0.25"],
                            ['1/8', "0.125"],
                            ['1/16', "0.0625"],
                            ['2', "2"],
                            ['4', "4"],
                        ]), "rhythm")
                        .appendField(Blockly.Msg.RHYTHM);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //播放旋律
            Blockly.Blocks.playMelody = {
                init: function () {
                    this.setColour(color_music);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PLAYMELODYPIN)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p10', "pin10"],
                        ]), "playPin") 
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PLAYMELODY)
                        .appendField(new Blockly.FieldDropdown([
                            ['dadadum', "music.DADADADUM"],
                            ['entertainer', "music.ENTERTAINER"],
                            ['prelude', "music.PRELUDE"],
                            ['ode', "music.ODE"],
                            ['nyan', "music.NYAN"],
                            ['ring tone', "music.RINGTONE"],
                            ['funk', "music.FUNK"],
                            ['blues', "music.BLUES"],
                            ['birthday song', "music.BIRTHDAY"],
                            ['wedding', "music.WEDDING"],
                            ['funereal', "music.FUNERAL"],
                            ['punchline', "music.PUNCHLINE"],
                            ['badd', "music.BADDY"],
                            ['chase', "music.CHASE"],
                            ['bading', "music.BA_DING"],
                            ['jump up', "music.JUMP_UP"],
                            ['jump down', "music.JUMP_DOWN"],
                            ['power up', "music.POWER_UP"],
                            ['power down', "music.POWER_DOWN"],
                        ]), "song")
                        .appendField(Blockly.Msg.REPEAT)
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.PLAYONCE, "once"],
                            [Blockly.Msg.INFINITECYCLE, "loop"],
                        ]), "frequency");
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //stopMelody
            
            Blockly.Blocks.stopMelody = {
                init: function () {
                    this.setColour(color_music);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.STOPMELODY)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p10', "pin10"],
                        ]), "stopPin") 
                        this.appendDummyInput("")
                        .appendField(Blockly.Msg.STOPMUSIC)
                    // .appendField(new Blockly.FieldDropdown([
                    //     ['全部', "播放一次"],
                    //     ['foreground', "foreground"],
                    //     ['background', "background"],
                    // ]), "rhythm");
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //将节奏更改为（bpm）  Change rhythm to
            Blockly.Blocks.bpmChange = {
                init: function () {
                    this.setColour(color_music);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.CHANGERHYTHM)
                    this.appendValueInput("bpm", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //将节奏设定为（bpm）
            Blockly.Blocks.bpmSetting = {
                init: function () {
                    this.setColour(color_music);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.SETRHYTHM)
                    this.appendValueInput("bpm", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //Led
            //绘图
            Blockly.Blocks.drawing = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DRAW)
                        .appendField(Blockly.Msg.XAXIS)
                    this.appendValueInput("x", Number)
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.YAXIS)
                    this.appendValueInput("y", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //取消绘图
            Blockly.Blocks.cancelMapping = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.CANCELDRAW)
                        .appendField(Blockly.Msg.XAXIS)
                    this.appendValueInput("x", Number)
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.YAXIS)
                    this.appendValueInput("y", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //切换绘图
            Blockly.Blocks.switchMapping = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.XAXIS)
                    this.appendValueInput("x", Number)
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.YAXIS)
                    this.appendValueInput("y", Number)
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.SWITCH)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //点图
            Blockly.Blocks.spotMapping = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.POINT)
                        .appendField(Blockly.Msg.XAXIS)
                    this.appendValueInput("x", Number)
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.YAXIS)
                    this.appendValueInput("y", Number)
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ISLIGHT)
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
                    this.setOutput(true, 'Boolean');
                    this.setTooltip('');
                }
            };
        
            //绘制条形图
            Blockly.Blocks.drawBarType = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DRAWBARCHART)
                        .appendField(Blockly.Msg.XAXIS)
                    this.appendValueInput("x", Number)
                    this.appendDummyInput("")
                        // .appendField("最高")
                        .appendField(Blockly.Msg.MAX)
                    this.appendValueInput("y", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //绘图 加入亮度条件
            Blockly.Blocks.drawingLight = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.DRAW)
                    .appendField(Blockly.Msg.XAXIS)
                    this.appendValueInput("x", Number)
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.YAXIS)
                    this.appendValueInput("y", Number);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.BRIGHTNESS)
                        this.appendValueInput("brightness", Number);
                        // .appendField(new Blockly.FieldDropdown([
                        //     ['9', "9"],
                        //     ['8', "8"],
                        //     ['7', "7"],
                        //     ['6', "6"],
                        //     ['5', "5"],
                        //     ['4', "4"],
                        //     ['3', "3"],
                        //     ['2', "2"],
                        //     ['1', "1"],
                        //     ['0', "0"],
                        // ]), "brightness")
                    // this.appendValueInput("brightness", Number);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //亮度
            Blockly.Blocks.brightness = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.BRIGHTNESS)
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //设置亮度
            Blockly.Blocks.setBrightness = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.SETBRIGHTNESS)
                    this.appendValueInput("brightness", Number);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //停止动画
            Blockly.Blocks.stopAnimation = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")   
                        .appendField(Blockly.Msg.STOPANIMATION)
                        // .appendField("停止动画")
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //wifi
            //无线设置组
            Blockly.Blocks.wifiSetting = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.WIRELESSSETTINGSGROUP)
                        // .appendField("无线设置组")
                    this.appendValueInput("setWifi", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
             //打开关闭无线
            Blockly.Blocks.openWifi = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                        
                        // .appendField("无线设置组")
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.OPEN, "on()"],
                            [Blockly.Msg.CLOSE, "off()"],
                        ]), "wifiSwitch")
                        .appendField(Blockly.Msg.MICROBIT_WIFI)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
        
            //无线发送数字
            Blockly.Blocks.wifiSendNumber = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WIRELESSDIGITAL)
                    this.appendValueInput("setWifiNumber", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
        
            //无线发送值
            Blockly.Blocks.wifiSettingValue = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WIRELESSTRANSMISSIONVALUE)
                        // .appendField("无线发送值")
                    this.appendValueInput("setWifiName", String)
                    this.appendDummyInput("")
                        .appendField("=")
                    this.appendValueInput("setWifiValue", String)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
        
            //无线发送字符串
            Blockly.Blocks.wifiSettingString = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WIRELESSSENDSTRING)
                        // .appendField("无线发送字符串")
                    this.appendValueInput("setwifiString", String)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //无线接收数据
            Blockly.Blocks.receivingData = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DATARECEIVEDWIRELESSLY)
                        // .appendField("无线接收到的数据")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //在无线接收到数据时运行    
            Blockly.Blocks.receivingDataStatusOne = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.RECEIVEDWIRELESSLY)
                        // .appendField("在无线接收到数据时运行")
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(false);
                    this.setNextStatement(false);
                    this.setTooltip('');
                }
            };
        
            //在无线接收到数据时运行
            Blockly.Blocks.receivingDataStatusTwo = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.RECEIVEDSTRINGWIRELESSLY)
                        // .appendField("在无线接收到字符串数据时运行")
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(false);
                    this.setNextStatement(false);
                    this.setTooltip('');
                }
            };
        
        
            Blockly.Blocks.receivingDataStatusThree = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.RECEIVEDKEYVALUEWIRELESSLY)
                        // .appendField("在无线接收到key-value数据时运行")
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(false);
                    this.setNextStatement(false);
                    this.setTooltip('');
                }
            };
        
            //接收到的数据包
            Blockly.Blocks.packetsReceived = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                        // .appendField("接收到的数据包")
                        .appendField(Blockly.Msg.PACKETSRECEIVED)
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.TIME, "time"]
                        ]), "weightgetas")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //无线设置发射功率
            Blockly.Blocks.wifiTansmitPower = {
                init: function () {
                    this.setColour(color_wifi);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.WIRELESSSETTRANSMITPOWER)
                        // .appendField("无线设置发射功率")
                        .appendField(new Blockly.FieldDropdown([
                            ['6', "6"],
                            ['0', "0"],
                            ['1', "1"],
                            ['2', "2"],
                            ['3', "3"],
                            ['4', "4"],
                            ['5', "5"],
                            ['7', "7"]
                        ]), "power")
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //数学
            Blockly.Blocks.initData = {
                init: function () {
                    this.setColour(color_math);
                    this.appendValueInput("data", Number);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //余数
            Blockly.Blocks.remainder = {
                init: function () {
                    this.setColour(color_math);
                    this.appendValueInput("data1", Number);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.AND)
                    this.appendValueInput("data2", Number);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.REMAINDER)
                        // .appendField("的余数");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //两个数间的最大值于最小值
            Blockly.Blocks.betweenNumbers = {
                init: function () {
                    this.setColour(color_math);
                    this.appendValueInput("data1", Number);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.AND)
                        // .appendField("与");
                    this.appendValueInput("data2", Number);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.IN)
                        // .appendField("中的")
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.MIN, "min"],
                            [Blockly.Msg.MAX1, "max"],
                        ]), "most")
                        this.appendDummyInput("")
                        .appendField(Blockly.Msg.VALUE)
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //绝对值
            Blockly.Blocks.absoluteValue = {
                init: function () {
                    this.setColour(color_math);
                    this.appendValueInput("absolute", String);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.ABS)
                        // .appendField("的绝对值");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //平方根
            Blockly.Blocks.squareRoot = {
                init: function () {
                    this.setColour(color_math);
                    this.appendDummyInput("")
                        .appendField(new Blockly.FieldDropdown([
                            ['sqrt', "sqrt"],
                            ['sin', "sin"],
                            ['cos', "cos"],
                            ['tan', "tan"],
                            ['atan2', "atan2"],
                        ]), "type");
                    this.appendValueInput("data", Number);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //选取随机数
            Blockly.Blocks.selectRandomNumber = {
                init: function () {
                    this.setColour(color_math);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.RANDOM)
                        .appendField(Blockly.Msg.RANGE)
                        // .appendField("选取随机数。范围为");
                    this.appendValueInput("data1", Number);
                    this.appendDummyInput("")
                        .appendField("~");
                    this.appendValueInput("data2", Number);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //随机选取true或者false
            Blockly.Blocks.randomBoolean = {
                init: function () {
                    this.setColour(color_math);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.RANDOMBOOLEAN)
                        // .appendField("随机选取true 或 false");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
                    this.setOutput(true, 'Boolean');
                    this.setTooltip('');
                }
            };
            
            //transferInt
            Blockly.Blocks.transferInt = {
                init: function () {
                    this.setColour(color_math);
                    // .appendField("长度");
                    this.appendValueInput("data", Number)
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.TRANSFERINT)
                        // .appendField("随机选取true 或 false");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };

            Blockly.Blocks.listLength = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ARRAY)
                        // .appendField("数组")
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['Test List', "Test List"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.LENGTH)
                        // .appendField("长度");
                    this.appendValueInput("index", Number)
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //获取数组索引得值
            Blockly.Blocks.getListIndexValue = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ARRAY)
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['Test List', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.GETINDEX);
                    this.appendValueInput("index", Number)
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.VALUE);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //设置数组索引得值
            Blockly.Blocks.setListIndexValue = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.ARRAY)
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.INDEX);
                        // .appendField("中索引");
                    this.appendValueInput("index", Number);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.VALUESET);
                        // .appendField("的值设置为");
                    this.appendValueInput("value", String);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //添加值到list中
            Blockly.Blocks.addValueToList = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        .appendField("   ")
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.VALUE);
                        // .appendField("将值");
                    this.appendValueInput("value", String);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ADDTOEND);
                        // .appendField("添加到结尾");
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //获取并移除数组中最后一个值
            Blockly.Blocks.removeEndValue = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.GETANDREMOVE)
                        // .appendField("获取并移除")
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            // ['列表', "列表"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.LASTVALUE);
                        // .appendField("中的最后一个值");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //查找某个值在数组中的下标
            Blockly.Blocks.getValuePosition = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.FIND);
                        // .appendField("查找");
                    this.appendValueInput("value", String);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.INDEX);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //获取并移除数组中第一个值
            Blockly.Blocks.removeStartValue = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        // .appendField("获取并移除")
                        .appendField(Blockly.Msg.GETANDREMOVE)
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.STARTVALUE);
                        // .appendField("中的第一个值");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //添加值到数组起始位置中
            Blockly.Blocks.addValueToListHead = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        .appendField("   ")
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.INSERTATBEGIN);
                        // .appendField("在开头插入");
                    this.appendValueInput("value", String);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //添加值到列表中某个位置
            Blockly.Blocks.addValueToListPosition = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        .appendField("   ")
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        // .appendField("在");
                        .appendField(Blockly.Msg.STAY);
                    this.appendValueInput("index", Number);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.INSERTVALUE);
                        // .appendField("处插入值");
                    this.appendValueInput("value", String);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //移除列表某处的值
            Blockly.Blocks.removePositionValue = {
                init: function () {
                    this.setColour(color_list);
                    this.appendDummyInput("")
                        .appendField(new Blockly.FieldDropdown([
                            ['list', "list"],
                            ['文本列表', "文本列表"],
                        ]), "weightgetas")
                        .appendField(Blockly.Msg.REMOVE)
                        .appendField(Blockly.Msg.INDEX);
                        // .appendField("移除");
                    this.appendValueInput("index", Number);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.VALUE);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //文本
            //空值
            Blockly.Blocks.nullValue = {
                init: function () {
                    this.setColour(color_text);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ENTERVALUE);
                    this.appendValueInput("inputText", String);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //返回字符的长度
            Blockly.Blocks.returnStringLength = {
                init: function () {
                    this.setColour(color_text);
                    this.appendValueInput("inputText", String);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.LENGTH);
                        // .appendField("的长度");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //比较两个字符串
            Blockly.Blocks.comparativeText = {
                init: function () {
                    this.setColour(color_text);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.COMPARE);
                        // .appendField("比较");
                    this.appendValueInput("inputText1", String);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.AND);
                        // .appendField("与");
                    this.appendValueInput("inputText2", String);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //获取字符串中的一部分 Starting position
            Blockly.Blocks.getSubString = {
                init: function () {
                    this.setColour(color_text);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.GET);
                    this.appendValueInput("inputText", String);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.STRING)
                        .appendField(Blockly.Msg.STARTPOSITION);
                    this.appendValueInput("startPosition", Number);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.STRLENGTH);
                        // .appendField(",长度");
                    this.appendValueInput("length", Number);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //判断字符串是否为空
            Blockly.Blocks.isEmptyText = {
                init: function () {
                    this.setColour(color_text);
                    this.appendValueInput("inputText", String)
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ISEMPTY)
                        // .appendField("为空")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
                    this.setOutput(true, 'Boolean');
                    this.setTooltip('');
                }
            };
        
            //将字符串转化为number类型
            Blockly.Blocks.parseToNumber = {
                init: function () {
                    this.setColour(color_text);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.PARSETONUMBER)
                    this.appendValueInput("inputText", String)
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //获取字符串中的一个字符Extract character position
            Blockly.Blocks.getIndexChar = {
                init: function () {
                    this.setColour(color_text);
                    this.appendDummyInput("")
                        // .appendField("从")
                        .appendField(Blockly.Msg.FROM)
                    this.appendValueInput("inputText", String)
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.EXTRACTCHARACTERPOSITON);
                        // .appendField("中提取字符 位置");
                    this.appendValueInput("startPosition", Number);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //提取字符代码中的文本 Extract character code
            Blockly.Blocks.extractText = {
                init: function () {
                    this.setColour(color_text);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.EXTRACTCHARACTERCODE)
                        // .appendField("提取字符代码")
                    this.appendValueInput("inputText", Number)
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.TEXT);
                        // .appendField("中的文本");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //convert to text
            Blockly.Blocks.convertToText = {
                init: function () {
                    this.setColour(color_text);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.NUMBER)
                    this.appendValueInput("integer", Number)
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.TOTEXT);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //图像
            //创建图像
            Blockly.Blocks.createImage = {
                init: function init() {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.CREATEIMAGE);
                        // .appendField("创建图像");
                    this.appendDummyInput('').appendField(new Blockly.FieldMatrix(), 'CHOICE');
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                    this.setColour(color_images, Blockly.Colours.motion.secondary, Blockly.Colours.motion.tertiary);
                }
            };
        
            //显示图像
            Blockly.Blocks.showImage = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.CREATEIMAGE);
                        // .appendField("显示图像");
                    this.appendValueInput("myImage", String);
                    this.appendDummyInput("")
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.UP, "UP"],
                            [Blockly.Msg.DOWN, "DOWN"],
                            [Blockly.Msg.LEFT, "LEFT"],
                            [Blockly.Msg.RIGHT, "RIGHT"],
                        ]), "orientation");
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DEVIATION)
                        // .appendField("偏移") deviation
                    this.appendValueInput("position", Number);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
           //滚动图像 Scroll image
           Blockly.Blocks.rollImage = {
            init: function () {
                this.setColour(color_images);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.SCROLLIMAGE);
                    // .appendField("滚动图像");
                this.appendValueInput("myImage", String);
                this.appendDummyInput("")
                    .appendField(new Blockly.FieldDropdown([
                        [Blockly.Msg.UP, "UP"],
                        [Blockly.Msg.DOWN, "DOWN"],
                        [Blockly.Msg.LEFT, "LEFT"],
                        [Blockly.Msg.RIGHT, "RIGHT"],
                    ]), "orientation");
                this.appendDummyInput("")
                .appendField(Blockly.Msg.OFFSETTO) ;
                    // .appendField("偏移为")
                this.appendValueInput("position", Number);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.INTERVAL)
                    // .appendField("且间隔（ms）为");
                this.appendValueInput("time", Number);
                this.setPreviousStatement(true, null);
                this.setNextStatement(true, null);
                this.setTooltip('');
            }
        };
        
            //箭头图像 Arrow image
            Blockly.Blocks.arrowImage = {
                init: function () {
                    this.setColour(color_images);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ARROWIMAGE)
                        // .appendField("箭头图像")
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.NORTH, "north"],
                            [Blockly.Msg.NORTHEAST, "northeast"],
                            [Blockly.Msg.EAST, "east"],
                            [Blockly.Msg.SOUTHEAST, "southeast"],
                            [Blockly.Msg.SOUTH, "south"],
                            [Blockly.Msg.SOUTHWEST, "southwest"],
                            [Blockly.Msg.WEST, "west"],
                            [Blockly.Msg.NORTHWEST, "northwest"],
                        ]), "arrow")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //引脚  Digital read pin
            //数字读取引脚
            Blockly.Blocks.digitalReadPin = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DIGITALREADPIN)
                        // .appendField("数字读取引脚")
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p5', "pin5"],
                            ['p6', "pin6"],
                            ['p7', "pin7"],
                            ['p8', "pin8"],
                            ['p9', "pin9"],
                            ['p10', "pin10"],
                            ['p11', "pin11"],
                            ['p12', "pin12"],
                            ['p13', "pin13"],
                            ['p14', "pin14"],
                            ['p15', "pin15"],
                            ['p16', "pin16"],
                            ['p17', "pin17"],
                            ['p18', "pin18"],
                            ['p19', "pin19"],
                            ['p20', "pin20"],
                        ]), "pin")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
        
            //向引脚数字写入值  Direction pin
            Blockly.Blocks.writeDigitalValue = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.DIRECTIONPIN)
                        // .appendField("向 引脚")
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p5', "pin5"],
                            ['p6', "pin6"],
                            ['p7', "pin7"],
                            ['p8', "pin8"],
                            ['p9', "pin9"],
                            ['p10', "pin10"],
                            ['p11', "pin11"],
                            ['p12', "pin12"],
                            ['p13', "pin13"],
                            ['p14', "pin14"],
                            ['p15', "pin15"],
                            ['p16', "pin16"],
                            ['p17', "pin17"],
                            ['p18', "pin18"],
                            ['p19', "pin19"],
                            ['p20', "pin20"],
                        ]), "pin")
                        .appendField(Blockly.Msg.DIGITALWRITEPIN);
                        // .appendField("数字写入值");
                    this.appendValueInput("value", Number);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //模拟读取引脚
            Blockly.Blocks.analogReadPin = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.ANALOGREADPIN)
                        // .appendField("模拟读取 引脚")
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p10', "pin10"],
                        ]), "pin")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //向引脚数字写入模拟值
            Blockly.Blocks.writeAnalogValue = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.DIRECTIONPIN)
                        // .appendField("向 引脚")
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p5', "pin5"],
                            ['p6', "pin6"],
                            ['p7', "pin7"],
                            ['p8', "pin8"],
                            ['p9', "pin9"],
                            ['p10', "pin10"],
                            ['p11', "pin11"],
                            ['p12', "pin12"],
                            ['p13', "pin13"],
                            ['p14', "pin14"],
                            ['p15', "pin15"],
                            ['p16', "pin16"],
                            ['p17', "pin17"],
                            ['p18', "pin18"],
                            ['p19', "pin19"],
                            ['p20', "pin20"],
                        ]), "pin")
                        .appendField(Blockly.Msg.ANALOGWRITEPIN);
                        // .appendField("模拟写入");
                    this.appendValueInput("value", Number);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
           //映射
           Blockly.Blocks.mapping = {
            init: function () {
                this.setColour(color_pin);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.MAPPING);
                    // .appendField("映射");
                this.appendValueInput("mapping", Number);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.FROMLOW);
                    // .appendField("从低");
                this.appendValueInput("low", Number);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.FROMHIGH);
                    // .appendField("从高");
                this.appendValueInput("high", Number);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.TOLOW);
                    // .appendField("至低");
                this.appendValueInput("tolow", Number);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.TOHIGH);
                    // .appendField("至高");
                this.appendValueInput("tohigh", Number);
                this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                this.setOutput(true, 'String');
                this.setTooltip('');
            }
        };
        
        //向伺服机构写值
        Blockly.Blocks.writeServoValue = {
            init: function () {
                this.setColour(color_pin);
                this.appendDummyInput("")
                .appendField(Blockly.Msg.TOSERVOPIN)
                    // .appendField("向伺服机构 引脚")
                    .appendField(new Blockly.FieldDropdown([
                        ['p0', "pin0"],
                        ['p1', "pin1"],
                        ['p2', "pin2"],
                        ['p3', "pin3"],
                        ['p4', "pin4"],
                        ['p10', "pin10"],
                    ]), "pin")
                    .appendField(Blockly.Msg.WRITE);
                    // .appendField("写入");
                this.appendValueInput("value", Number);
                this.setPreviousStatement(true, null);
                this.setNextStatement(true, null);
                this.setTooltip('');
            }
        };
        
            //设置伺服机构脉冲
            Blockly.Blocks.setServoPulse = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.TOSERVOPIN)
                        // .appendField("向伺服机构 引脚")
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p10', "pin10"],
                        ]), "pin")
                        .appendField(Blockly.Msg.PULSESET);
                        // .appendField("脉冲设置为（ms）"); Pulse set to
                    this.appendValueInput("pulse", Number);
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            //当引脚状态改变时
            Blockly.Blocks.statusChangesEvent = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WHENPIN)
                        // .appendField("当引脚")
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p5', "pin5"],
                            ['p6', "pin6"],
                            ['p7', "pin7"],
                            ['p8', "pin8"],
                            ['p9', "pin9"],
                            ['p10', "pin10"],
                            ['p11', "pin11"],
                            ['p12', "pin12"],
                            ['p13', "pin13"],
                            ['p14', "pin14"],
                            ['p15', "pin15"],
                            ['p16', "pin16"],
                            ['p17', "pin17"],
                            ['p18', "pin18"],
                            ['p19', "pin19"],
                            ['p20', "pin20"],
                        ]), "pin")
                        .appendField(Blockly.Msg.PULSE)
                        // .appendField("脉冲为")
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.HIGH, "high"],
                            [Blockly.Msg.LOW, "low"],
                        ]), "status")
                    this.appendStatementInput('DO')
                        .appendField("");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //脉冲持续时间（μs） Pulse duration
            Blockly.Blocks.pulseDuration = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.PULSEDURATION);
                        // .appendField("脉冲持续时间（μs）");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //脉冲引脚持续时间（μs）——
            Blockly.Blocks.pulseDurationPin = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.PULSEDURATIONPIN)
                        // .appendField("脉冲持续时间（μs）引脚")
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p3', "pin3"],
                            ['p4', "pin4"],
                            ['p5', "pin5"],
                            ['p6', "pin6"],
                            ['p7', "pin7"],
                            ['p8', "pin8"],
                            ['p9', "pin9"],
                            ['p10', "pin10"],
                            ['p11', "pin11"],
                            ['p12', "pin12"],
                            ['p13', "pin13"],
                            ['p14', "pin14"],
                            ['p15', "pin15"],
                            ['p16', "pin16"],
                            ['p17', "pin17"],
                            ['p18', "pin18"],
                            ['p19', "pin19"],
                            ['p20', "pin20"],
                        ]), "pin")
                        .appendField(Blockly.Msg.PULSE)
                        // .appendField("脉冲为")
                        .appendField(new Blockly.FieldDropdown([
                            [Blockly.Msg.HIGH, "high"],
                            [Blockly.Msg.LOW, "low"],
                            // ['高', "高"],
                            // ['低', "低"],
                        ]), "status");
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //spi 写入
            Blockly.Blocks.spiWrite = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.SPIWRITE);
                        // .appendField("spi 写入");
                    this.appendValueInput("value", Number);
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'String');
                    this.setTooltip('');
                }
            };
        
            //spi 频率
            Blockly.Blocks.spiFrequency = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.SPIFREQUENCY);
                        // .appendField("spi 频率");
                    this.appendValueInput("value", Number);
                    this.appendDummyInput("")
                    .appendField("(HZ)");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //模拟设置音阶引脚
            Blockly.Blocks.setAnalogScalePin = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.SETANALOGSCALEPIN)
                    .appendField(new Blockly.FieldDropdown([
                        ['p0', "pin0"],
                        ['p1', "pin1"],
                        ['p2', "pin2"],
                        ['p3', "pin3"],
                        ['p4', "pin4"],
                        ['p10', "pin10"],
                    ]), "pin")
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.FREQUENCY)
                        // .appendField("模拟设置音阶引脚")
                    this.appendValueInput("frequency", Number);
                    this.appendDummyInput("")
                    .appendField("(HZ)");
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.DURATION)
                    this.appendValueInput("time", Number);
                    this.appendDummyInput("")
                    .appendField("(ms)");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //spi 格式 位数
            Blockly.Blocks.spiFormatDigits = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.SPIFORMATDIGITS);
                    this.appendDummyInput("")
                    .appendField(new Blockly.FieldDropdown([
                        ['8 bit', "8"],
                    ]), "value");
                        // .appendField("spi 格式 位数");
                    // this.appendValueInput("value", Number);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.MODEL);
                    this.appendDummyInput("")
                    .appendField(new Blockly.FieldDropdown([
                        ['Mode1', "0"],
                        ['Mode2', "1"],
                        ['Mode3', "2"],
                        ['Mode4', "3"],
                    ]), "mode");
                        // .appendField("模式");
                    // this.appendValueInput("mode", Number);
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //spi 设置引脚  SPI set pin MoSi
            Blockly.Blocks.spiSetPin = {
                init: function () {
                    this.setColour(color_pin);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.SPISETPINMOSI)
                        // .appendField("spi 设置引脚 MOSI")
                        .appendField(new Blockly.FieldDropdown([
                            ['p15', "pin15"],
                        ]), "mosi")
                        .appendField("MISO")
                        .appendField(new Blockly.FieldDropdown([
                            ['p14', "pin14"],
                        ]), "miso")
                        .appendField("SCLK")
                        .appendField(new Blockly.FieldDropdown([
                            ['p13', "pin13"],
                        ]), "sdk")
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            //串口
            // 串口打印字符串
            Blockly.Blocks.serialPrintingString = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.SERIALPRINTINGSTRING);
                        // .appendField("串口打印字符串");
                    this.appendValueInput("value", String)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 向串口写入一行
            Blockly.Blocks.writeLineToSerial = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WRITELINETOSERIAL);
                        // .appendField("向串口写入一行");
                    this.appendValueInput("value", String)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 串口写入数字
            Blockly.Blocks.writeNumberToSerial = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WRITENUMBERTOSERIAL);
                        // .appendField("串口写入数字");
                    this.appendValueInput("value", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 串口写入数值
            Blockly.Blocks.writeValueToSerial = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.WRITEVALUETOSERIAL);
                        // .appendField("串口写入数值");
                    this.appendValueInput("name", String)
                    this.appendDummyInput("")
                        .appendField("=");
                    this.appendValueInput("value", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 串口写入字符串
            Blockly.Blocks.writeStringToSerial = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WRITESTRINGTOSERIAL);
                        // .appendField("串口写入字符串")
                    this.appendValueInput("value", String)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 从串口读取行
            Blockly.Blocks.readLineToSerial = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.SERIALREADLINE);
                        // .appendField("从串口读取行")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            // 从串口读取，直到遇见标签
            Blockly.Blocks.readSerialData = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.SERIALREADLINEUNTIL)
                        // .appendField("从串口读取行，直至遇到")
                    this.appendValueInput("value", String)
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            // 从串口读取字符串
            Blockly.Blocks.readSerialString = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.READSTRINGTOSERIAL)
                        // .appendField("从串口读取字符串")
                    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
                    this.setOutput(true, 'Number');
                    this.setTooltip('');
                }
            };
        
            //串行 重定向 Serial redirection to
            Blockly.Blocks.serialRedirection = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                        // .appendField("串行 重定向到 TX")
                        .appendField(Blockly.Msg.SERIALREDIRECTION)
                        .appendField(Blockly.Msg.TX)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p8', "pin8"],
                            ['p12', "pin12"],
                            ['p13', "pin13"],
                            ['p14', "pin14"],
                            ['p15', "pin15"],
                            ['p16', "pin16"],
                            ['USB_TX', "USB_TX"],
                            ['USB_RX', "USB_RX"],
                        ]), "pinTX")
                        .appendField(Blockly.Msg.RX)
                        .appendField(new Blockly.FieldDropdown([
                            ['p0', "pin0"],
                            ['p1', "pin1"],
                            ['p2', "pin2"],
                            ['p8', "pin8"],
                            ['p12', "pin12"],
                            ['p13', "pin13"],
                            ['p14', "pin14"],
                            ['p15', "pin15"],
                            ['p16', "pin16"],
                            ['USB_TX', "USB_TX"],
                            ['USB_RX', "USB_RX"],
                        ]), "pinRX")
                        .appendField(Blockly.Msg.BAUDRATE)
                        // .appendField("波特率为")
                        .appendField(new Blockly.FieldDropdown([
                            ['115200', "115200"],
                            ['57600', "57600"],
                            ['38400', "38400"],
                            ['31250', "31250"],
                            ['28800', "28800"],
                            ['19200', "19200"],
                            ['14400', "14400"],
                            ['9600', "9600"],
                            ['4800', "4800"],
                            ['2400', "2400"],
                            ['1200', "1200"],
                        ]), "baudRate");
                    this.setPreviousStatement(true);
                    this.setNextStatement(true);
                    this.setTooltip('');
                }
            };
        
            // 串行 重定向到USB
            Blockly.Blocks.serialRedirectionUSB = {
                init: function () {
                    this.setColour(color_serial);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.SERIALREDIRECTIONUSB)
                        // .appendField("串行 重定向到USB")
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 重置
            Blockly.Blocks.reset = {
                init: function () {
                    this.setColour(color_control);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.RESET)
                        // .appendField("重置")
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 等待（μs）
            Blockly.Blocks.waiting = {
                init: function () {
                    this.setColour(color_control);
                    this.appendDummyInput("")
                    .appendField(Blockly.Msg.WAIT)
                        // .appendField("等待（μs）")
                    this.appendValueInput("value", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            // 显示屏显示
            Blockly.Blocks.displayShow = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DISPLAYSHOW)
                    this.appendValueInput("value", Number)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };
        
            Blockly.Blocks.displayShowClear = {
                init: function () {
                    this.setColour(color_display);
                    this.appendDummyInput("")
                        .appendField(Blockly.Msg.DISPLAYCLEARE)
                    this.setPreviousStatement(true, null);
                    this.setNextStatement(true, null);
                    this.setTooltip('');
                }
            };



//-----------------base model--------------------------------------------
//按键传感器 microbit_button
Blockly.Blocks.microbit_button = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/14.Button - Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_PIN)
            .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P14', "pin14"],
            ['P15', "pin15"],
            ]),"microbitButton")
            .appendField(Blockly.Msg.MICROBIT_ISBUTTON)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };

    //触摸传感器
    Blockly.Blocks.microbit_touch = {
        init:function(){
        this.setColour(base_color);
            this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/13.Touch-Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_PIN)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                ['P13', "pin13"],
                ['P14', "pin14"],
                ['P15', "pin15"],
            ]),"microbitTouch")
            .appendField(Blockly.Msg.MICROBIT_ISTOUCH)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
        this.setOutput(true, 'Boolean');
        this.setTooltip('');
        }   
    };

    //碰撞传感器
    Blockly.Blocks.microbit_knockswitch = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/2.Collision   Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_PIN)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                ['P13', "pin13"],
                ['P14', "pin14"],
                ['P15', "pin15"],
            ]),"knockswitch")
            .appendField(Blockly.Msg.MICROBIT_READKNOCKSWITCH)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
        this.setOutput(true, 'Boolean');
        this.setTooltip('');
        }
    };

    //旋转电位器
Blockly.Blocks.microbit_resistance = {
    init:function(){
      this.setColour(base_color);
      this.appendDummyInput("")
       .appendField(new Blockly.FieldImage(staticImg+"/16.Rotary  potentiometer.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_PIN)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P1', "pin1"],
            ['P2', "pin2"],
        ]),"resistance")
          .appendField(Blockly.Msg.MICROBIT_READRESISTANCE)
    this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
      this.setTooltip('');
    }
    };


     //旋转编码器初始化
    Blockly.Blocks.microbit_encoderInit = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/15.Rotary  encoder Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_ENCODERINIT)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P13', "pin13"],
            ]),"aPort")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_ENCODERBPORTINIT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
            ]),"bPort")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_ENCODERDPORTINIT)
            .appendField(new Blockly.FieldDropdown([
                ['P8', "pin8"],
                ['P15', "pin15"],
            ]),"dPort")
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setPreviousStatement(true, null);
           this.setNextStatement(true, null);
           this.setTooltip('');
        }
    };

    //旋转编码器按钮是否被按下
    Blockly.Blocks.microbit_encoderButtonPressed = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/15.Rotary  encoder Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_ENCODERBUTTON)
        this.appendDummyInput("")
        .appendField(Blockly.Msg.MICROBIT_ENCODERDPORTINIT)
        .appendField(new Blockly.FieldDropdown([
            ['P8', "pin8"],
            ['P15', "pin15"],
        ]),"dPort")
        this.appendDummyInput("")
        .appendField(Blockly.Msg.MICROBIT_ENCODERBUTTONISPRESSED)
        
        
        this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };

     //旋转编码器按获取编码值
     Blockly.Blocks.microbit_encoderPulse = {
        init:function(){
            this.setColour(base_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/15.Rotary  encoder Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_READENCODE)
            .appendField(Blockly.Msg.MICROBIT_PINA)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P13', "pin13"],
            ]),"aPort")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_PINB)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
            ]),"bPort")
            .appendField(Blockly.Msg.MICROBIT_ENCODERPULSE)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
            this.setTooltip('');
        }
    };



    //钢琴模块初始化端口
    Blockly.Blocks.microbit_pianoInit = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
         .appendField(new Blockly.FieldImage(staticImg+"/33.Touch  Piano.svg", 84, 42))
           .appendField(Blockly.Msg.MICROBIT_PIANO)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
           ]),"pianoCLK")
           .appendField(Blockly.Msg.MICROBIT_DIO)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
           ]),"pianoDIO")
           this.setPreviousStatement(true, null);
           this.setNextStatement(true, null);
           this.setTooltip('');
        }
    };

    //钢琴模块 获取钢琴值
    Blockly.Blocks.microbit_getPianoKey = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/33.Touch  Piano.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_GETPIANOKEY)
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setTooltip('');
        }
    };

    //钢琴模块
    Blockly.Blocks.microbit_piano = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/33.Touch  Piano.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_PIANOPRESS)
        .appendField(new Blockly.FieldDropdown([
            ['1', "1"],
            ['2', "2"],
            ['3', "3"],
            ['4', "4"],
            ['5', "5"],
            ['6', "6"],
            ['7', "7"],
            ['8', "8"],
        ]),"piano2")
        this.appendDummyInput("")
        .appendField(Blockly.Msg.MICROBIT_QUESTIONMARK)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };


    //矩阵键盘模块初始化端口
    Blockly.Blocks.microbit_maxtixKeyPadInit = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
         .appendField(new Blockly.FieldImage(staticImg+"/49.Matrix Keyboard Module.svg", 84, 42))
           .appendField(Blockly.Msg.MICROBIT_MAXTIXKEYPAD)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
           ]),"maxtixKeypadCLK")
           .appendField(Blockly.Msg.MICROBIT_DIO)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
           ]),"maxtixKeypadDIO")
           this.setPreviousStatement(true, null);
           this.setNextStatement(true, null);
           this.setTooltip('');
        }
    };

    //获取键盘值模块
    Blockly.Blocks.microbit_maxtixKeyPadGetValue = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/49.Matrix Keyboard Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_MAXTIXKEYPADGETVALUE)
        this.setPreviousStatement(true, null);
           this.setNextStatement(true, null);
           this.setTooltip('');
        }
    };

    //判断 键盘按钮值模块
    Blockly.Blocks.microbit_maxtixKeyPad = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/49.Matrix Keyboard Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_MAXTIXKEYPADPRESS)
        .appendField(new Blockly.FieldDropdown([
            ['0', "0"],
            ['1', "1"],
            ['2', "2"],
            ['3', "3"],
            ['4', "4"],
            ['5', "5"],
            ['6', "6"],
            ['7', "7"],
            ['8', "8"],
            ['9', "9"],
            ['A', "10"],
            ['B', "11"],
            ['C', "12"],
            ['D', "13"],
            ['*', "14"],
            ['#', "15"],
        ]),"maxtixKeypad")
        this.appendDummyInput("").appendField("?")
        this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };


    //滑动电位器
    Blockly.Blocks.microbit_slipresistance = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/32.Slide  Potentiometer.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_PIN)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
            ]),"slipresistance")
            .appendField(Blockly.Msg.MICROBIT_READSLIPRESISTANCE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    
    //摇杆模块初始化端口
    Blockly.Blocks.microbit_rockInit = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
         .appendField(new Blockly.FieldImage(staticImg+"/31.Rocker - Module.svg", 84, 42))
           .appendField(Blockly.Msg.MICROBIT_ROCK)
           .appendField(Blockly.Msg.MICROBIT_ROCKXAXIS)
           .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P13', "pin13"],
           ]),"rockX")
           .appendField(Blockly.Msg.MICROBIT_ROCKYAXIS)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
           ]),"rockY")
           .appendField(Blockly.Msg.MICROBIT_ROCKBUTTON)
           .appendField(new Blockly.FieldDropdown([
            ['P8', "pin8"],
            ['P15', "pin15"],
           ]),"rockB")
           this.setPreviousStatement(true, null);
           this.setNextStatement(true, null);
           this.setTooltip('');
        }
    };
    // 获取摇杆
  Blockly.Blocks.microbit_rockData = {
    init:function(){
      this.setColour(base_color);
      this.appendDummyInput("")
      .appendField(new Blockly.FieldImage(staticImg+"/31.Rocker - Module.svg", 84, 42))
          .appendField(Blockly.Msg.MICROBIT_PIN)
          .appendField(new Blockly.FieldDropdown([
            ['P8', "pin8"],
            ['P15', "pin15"],
           ]),"rockB")
           .appendField(Blockly.Msg.MICROBIT_READROCKDATA)
          this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
          this.setOutput(true, 'Boolean');
          this.setTooltip('');
    }
  };

  // 获取摇杆值
  Blockly.Blocks.microbit_rock = {
    init:function(){
      this.setColour(base_color);
      this.appendDummyInput("")
      .appendField(new Blockly.FieldImage(staticImg+"/31.Rocker - Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_PIN)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P13', "pin13"],
           ]),"rockX")
           .appendField(Blockly.Msg.MICROBIT_PIN)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
           ]),"rockY")
          .appendField(Blockly.Msg.MICROBIT_READROCK)
          .appendField(new Blockly.FieldDropdown([
            [Blockly.Msg.MICROBIT_ROCKXAXIS, "x"],
            [Blockly.Msg.MICROBIT_ROCKYAXIS, "y"],
          ]),"rock2")
          .appendField(Blockly.Msg.MICROBIT_ROCKVALUE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
    }
  };
//===================================显示器===========================
  //LED
    Blockly.Blocks.microbit_led = {
        init:function(){
        this.setColour(show_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/4.LED-Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_LED)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                ['P13', "pin13"],
                ['P14', "pin14"],
                ['P15', "pin15"],
            ]),"ledPort")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_STATUS)
            .appendField(new Blockly.FieldDropdown([
            [Blockly.Msg.MICROBIT_OPEN, "True"],
            [Blockly.Msg.MICROBIT_CLOSE, "False"],
            ]),"ledStatus")
            this.setPreviousStatement(true, null);
           this.setNextStatement(true, null);
           this.setTooltip('');
        }
    };

       
//lcd配置地址
Blockly.Blocks.microbit_lcdinit = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
      .appendField(Blockly.Msg.MICROBIT_LCDINIT_ADDRESS)
    this.appendValueInput("microbit_lcdinits", Number)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };
  
  //lcd清屏
  Blockly.Blocks.microbit_lcdClear = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(Blockly.Msg.MICROBIT_LCDPRINT)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };

  //lcd打开显示屏
  Blockly.Blocks.microbit_lcdScreen = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_LCDON, "on()"],
        [Blockly.Msg.MICROBIT_LCDOFF, "off()"]
    ]), "lcdScreen")
      .appendField(Blockly.Msg.MICROBIT_LCDSCREEN)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };
  //lcd背光
  Blockly.Blocks.microbit_lcdBackLight = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_LCDON, "on()"],
        [Blockly.Msg.MICROBIT_LCDOFF, "off()"]
    ]), "lcdBackLight")
      .appendField(Blockly.Msg.MICROBIT_LCDBACKLIGHT)
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };


  //lcd移动
  Blockly.Blocks.microbit_lcdShift = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
    .appendField(Blockly.Msg.MICROBIT_LCDSHIFT)
    .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_LCDLEFT, "left()"],
        [Blockly.Msg.MICROBIT_LCDRIGHT, "right()"]
    ]), "lcdShift");
    this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);
    this.setTooltip('');
    }
  };

  //lcd显示
  Blockly.Blocks.microbit_lcdposition = {
    init:function(){
        this.setColour(show_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/39.LCD_1602.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_LCDSHOWROW)
        .appendField(Blockly.Msg.MICROBIT_ROW)
        this.appendValueInput("row", Number)
        this.appendDummyInput("")
        .appendField(Blockly.Msg.MICROBIT_COL)
        this.appendValueInput("col", Number)
        this.appendDummyInput("")
        .appendField(Blockly.Msg.MICROBIT_LCDSHOW)
        this.appendValueInput("lcdStr", String)
        
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
    }
  };


    //  tm1650数码管初始化
    Blockly.Blocks.microbit_tm1650Init = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650)
            .appendField(new Blockly.FieldDropdown([
                ["0", "0"],
                ["1", "1"],
                ["2", "2"],
                ["3", "3"],
                ["4", "4"],
                ["5", "5"],
                ["6", "6"],
                ["7", "7"],
                [Blockly.Msg.MICROBIT_TM1650CLOSE, ""]
            ]), "tm1650Intensity");
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

  

     // tm1650数码管展示
     Blockly.Blocks.microbit_tm1650display = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650DISPLAY)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1650FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1650SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1650THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1650FORTH, "3"],
            ]),"TM1650Bit");
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1650DISPLAYDATA)
            this.appendValueInput("tm1650Data", Number)
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };


    // tm1650数码管展示小数点
    Blockly.Blocks.microbit_tm1650PointDisplay = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650POINTDISPLAY)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1650FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1650SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1650THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1650FORTH, "3"],
            ]),"TM1650PointBit");
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_LCDSHOW);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_TM1650OPEN, "True"],
                [Blockly.Msg.MICROBIT_TM1650CLOSE, "False"],
                ]),"tm1650Point")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };



    // tm1650数码管显示数字  
    Blockly.Blocks.microbit_tm1650ShowNumber = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650SHOWNUMBER)
            this.appendValueInput("tm1650Number", Number)
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    

    // tm1650数码管清屏
    Blockly.Blocks.microbit_tm1650Clear = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650CLEAR);
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };


  

    // tm1637数码管初始化
    Blockly.Blocks.microbit_tm1637Init = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
           ]),"tm1637CLK")
           .appendField(Blockly.Msg.MICROBIT_DIO)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
           ]),"tm1637DIO")
           this.appendDummyInput("")
           .appendField(Blockly.Msg.MICROBIT_TM1637INTENSITY)
           .appendField(new Blockly.FieldDropdown([
            ["7", "7"],
            ["0", "0"],
            ["1", "1"],
            ["2", "2"],
            ["3", "3"],
            ["4", "4"],
            ["5", "5"],
            ["6", "6"]
        ]), "tm1637Intensity");
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

     // tm1637数码管展示
     Blockly.Blocks.microbit_tm1637display = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAY)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1637FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1637SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1637THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1637FORTH, "3"],
            ]),"TM1637Bit");
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAYDATA)
            this.appendValueInput("tm1637Data", Number)
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAYPOINT)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_OPEN, "True"],
                [Blockly.Msg.MICROBIT_CLOSE, "False"],
            ]),"tm1637Point")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

      // tm1650数码管显示数字  
      Blockly.Blocks.microbit_tm1637ShowNumber = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637SHOWNUMBER)
            this.appendValueInput("tm1637Number", Number)
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAYPOINT)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_OPEN, "True"],
                [Blockly.Msg.MICROBIT_CLOSE, "False"],
            ]),"tm1637Point")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    // tm1637数码管清屏
    Blockly.Blocks.microbit_tm1637Clear = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637CLEAR)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1637FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1637SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1637THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1637FORTH, "3"],
             [Blockly.Msg.MICROBIT_TM1637ALL, ""],
            ]),"TM1637Bit1");
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

     // 7219初始化
     Blockly.Blocks.microbit_matrix7219Init = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/24. 8x8.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_MATRIX7219)
            .appendField(Blockly.Msg.MICROBIT_DIN)
           .appendField(new Blockly.FieldDropdown([
            ['P15', "pin15"],
            ['P8', "pin8"],
           ]),"matrix_din")
           .appendField(Blockly.Msg.MICROBIT_CS)
           .appendField(new Blockly.FieldDropdown([
            ['P2', "pin2"],
            ['P1', "pin1"],
           ]),"matrix_cs")
           .appendField(Blockly.Msg.MICROBIT_CLK)
           .appendField(new Blockly.FieldDropdown([
            ['P13', "pin13"],
            ['P0', "pin0"],
           ]),"matrix_sda")
           this.appendDummyInput("")
           .appendField(Blockly.Msg.MICROBIT_MATRIX7219INTENSITY)
           .appendField(new Blockly.FieldDropdown([
            ['7', "7"],
            ['1', "1"],
            ['2', "2"],
            ['3', "3"],
            ['4', "4"],
            ['5', "5"],
            ['6', "6"],
            ['8', "8"],
            ['9', "9"],
            ['10', "10"],
            ['11', "11"],
            ['12', "12"],
            ['13', "13"],
            ['14', "14"],
            ['15', "15"],
           ]),"initIntensity")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    // 7219 点显示亮度
    Blockly.Blocks.microbit_matrix7219SetPixel = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/24. 8x8.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_MATRIX7219SETPIXEL)
            .appendField(new Blockly.FieldDropdown([
                ['0', "0"],
                ['1', "1"],
                ['2', "2"],
                ['3', "3"],
                ['4', "4"],
                ['5', "5"],
                ['6', "6"],
                ['7', "7"],
               ]),"matrixX")
            // this.appendValueInput("matrixX", Number)
            .appendField(Blockly.Msg.MICROBIT_MATRIX7219X)
            .appendField(new Blockly.FieldDropdown([
                ['0', "0"],
                ['1', "1"],
                ['2', "2"],
                ['3', "3"],
                ['4', "4"],
                ['5', "5"],
                ['6', "6"],
                ['7', "7"],
               ]),"matrixY")
            // this.appendValueInput("matrixY", Number)
            .appendField(Blockly.Msg.MICROBIT_MATRIX7219Y)
            .appendField(new Blockly.FieldDropdown([
                ['7', "7"],
                ['1', "1"],
                ['2', "2"],
                ['3', "3"],
                ['4', "4"],
                ['5', "5"],
                ['6', "6"],
                ['8', "8"],
                ['9', "9"],
                ['10', "10"],
                ['11', "11"],
                ['12', "12"],
                ['13', "13"],
                ['14', "14"],
                ['15', "15"],
               ]),"intensity")
            // this.appendValueInput("intensity", Number)
            .appendField(Blockly.Msg.MICROBIT_MATRIX7219INTENSITY)
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    // 7219 点阵图像 
    Blockly.Blocks.microbit_matrix7219Draw = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/24. 8x8.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_MATRIX7219DRAM)
            this.appendDummyInput('').appendField(new Blockly.LatticeAdapter(), 'lattice');
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

//红绿灯初始化端口  
Blockly.Blocks.microbit_trafficlightsInit = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
     .appendField(new Blockly.FieldImage(staticImg+"/27.Water  ljght Module.svg", 84, 42))
       .appendField(Blockly.Msg.MICROBIT_TRAFFICLIGHTSINIT)
       .appendField(Blockly.Msg.MICROBIT_TRIFFICLIGHTSRED)
       .appendField(new Blockly.FieldDropdown([
        ['P8', "pin8"],
        ['P15', "pin15"],
       ]),"red")
       .appendField(Blockly.Msg.MICROBIT_TRIFFICLIGHTSGREEN)
       .appendField(new Blockly.FieldDropdown([
        ['P0', "pin0"],
        ['P13', "pin13"],
       ]),"green")
       .appendField(Blockly.Msg.MICROBIT_TRIFFICLIGHTSYELLOW)
       .appendField(new Blockly.FieldDropdown([
        ['P1', "pin1"],
        ['P2', "pin2"],
       ]),"yellow")
       this.setPreviousStatement(true, null);
       this.setNextStatement(true, null);
       this.setTooltip('');
    }
};

    //红绿灯
Blockly.Blocks.microbit_trafficlights = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
     .appendField(new Blockly.FieldImage(staticImg+"/27.Water  ljght Module.svg", 84, 42))
       .appendField(Blockly.Msg.MICROBIT_TRIFFICLIGHTSRED)
       .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_BRIGHT, "True"],
        [Blockly.Msg.MICROBIT_EXTINCT, "False"],
      ]),"trafficlightsRed")
      .appendField(Blockly.Msg.MICROBIT_TRIFFICLIGHTSGREEN)
      .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_BRIGHT, "True"],
        [Blockly.Msg.MICROBIT_EXTINCT, "False"],
      ]),"trafficlightsGreen")
      .appendField(Blockly.Msg.MICROBIT_TRIFFICLIGHTSYELLOW)
       .appendField(new Blockly.FieldDropdown([
        [Blockly.Msg.MICROBIT_BRIGHT, "True"],
        [Blockly.Msg.MICROBIT_EXTINCT, "False"],
       ]),"trafficlightsYellow")
       this.appendValueInput("lightTime1", Number)
       .appendField(Blockly.Msg.MICROBIT_SHOWTIME)
    this.setPreviousStatement(true,null);
      this.setNextStatement(true,null);
    this.setTooltip('');
    }
    };


    //RGB初始化端口
Blockly.Blocks.microbit_rgbcolorInit = {
    init:function(){
    this.setColour(show_color);
    this.appendDummyInput("")
     .appendField(new Blockly.FieldImage(staticImg+"/10.RGB-Module.svg", 84, 42))
       .appendField(Blockly.Msg.MICROBIT_RGBINIT)
       .appendField(Blockly.Msg.MICROBIT_RGBRED)
       .appendField(new Blockly.FieldDropdown([
        ['P1', "pin1"],
        ['P2', "pin2"],
       ]),"red")
       .appendField(Blockly.Msg.MICROBIT_RGBGREEN)
       .appendField(new Blockly.FieldDropdown([
        ['P8', "pin8"],
        ['P15', "pin15"],
       ]),"green")
       .appendField(Blockly.Msg.MICROBIT_RGBBLUE)
       .appendField(new Blockly.FieldDropdown([
        ['P0', "pin0"],
        ['P13', "pin13"],
       ]),"blue")
       this.setPreviousStatement(true, null);
       this.setNextStatement(true, null);
       this.setTooltip('');
    }
};

// //rgb
    //rgb颜色
    Blockly.Blocks.microbit_rgbcolor = {
        init:function(){
        this.setColour(show_color);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/10.RGB-Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_RGBSMG)
        this.appendValueInput("COLOR", Number)
            // this.appendValueInput("rgbr", Number)
            .appendField(Blockly.Msg.MICROBIT_DISPLAYCOLOR)
            // this.appendValueInput("rgbg", Number)
            // .appendField(Blockly.Msg.MICROBIT_RGBG)
            // this.appendValueInput("rgbb", Number)
            // .appendField(Blockly.Msg.MICROBIT_RGBB)
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
        }
    };

//=============================执行器==============================
    //直流电机
    Blockly.Blocks.microbit_motor = {
        init:function(){
            this.setColour(color_do);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/21.Motor-Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_MOTOR)
            .appendField(new Blockly.FieldDropdown([
                    ['P1', "pin1"],
                    ['P2', "pin2"],
                    ['P12', "pin12"],
                    ['P14', "pin14"],
                    ['P16', "pin16"],
            ]),"INA")
            .appendField(Blockly.Msg.MICROBIT_MOTORINB)
            .appendField(new Blockly.FieldDropdown([
                    ['P1', "pin1"],
                    ['P8', "pin8"],
                    ['P12', "pin12"],
                    ['P13', "pin13"],
                    ['P15', "pin15"],
            ]),"INB")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_DIRECTION)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_FORWARD, "forward"],
                [Blockly.Msg.MICROBIT_REVERSE, "reverse"],
            ]),"direction")
                this.appendValueInput("motorSpeed", Number)
                .appendField(Blockly.Msg.MICROBIT_SPEED)
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    //无源蜂鸣器 ph_buzzer
    Blockly.Blocks.microbit_passive_buzzer = {
        init:function(){
        this.setColour(color_do);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/7.Passlve  Buzzer Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_PASSIVEBUZZER)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
        ]),"passiveBuzzer")
        .appendField(Blockly.Msg.MICROBIT_PLAYMELODY)
        .appendField(new Blockly.FieldDropdown([
            ['DADADADUM', "music.DADADADUM"],
            ['ENTERTAINER', "music.ENTERTAINER"],
            ['PRELUDE', "music.PRELUDE"],
            ['ODE', "music.ODE"],
            ['NYAN', "music.NYAN"],
            ['RINGTONE', "music.RINGTONE"],
            ['FUNK', "music.FUNK"],
            ['BLUES', "music.BLUES"],
            ['BIRTHDAY', "music.BIRTHDAY"],
            ['WEDDING', "music.WEDDING"],
            ['FUNERAL', "music.FUNERAL"],
            ['PUNCHLINE', "music.PUNCHLINE"],
            ['BADDY', "music.BADDY"],
            ['CHASE', "music.CHASE"],
            ['BA_DING', "music.BA_DING"],
            ['JUMP_UP', "music.JUMP_UP"],
            ['JUMP_DOWN', "music.JUMP_DOWN"],
            ['POWER_UP', "music.POWER_UP"],
            ['POWER_DOWN', "music.POWER_DOWN"],
        ]), "song")
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
        }
    };


    //有源蜂鸣器模块
    Blockly.Blocks.microbit_buzzer = {
        init:function(){
        this.setColour(color_do);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/1.Buzzer  Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_BUZZER)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P14', "pin14"],
            ['P15', "pin15"],
        ]),"buzzer")
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_STATUS)
        .appendField(new Blockly.FieldDropdown([
            [Blockly.Msg.MICROBIT_OPEN, "True"],
            [Blockly.Msg.MICROBIT_CLOSE, "False"],
            ]),"buzzerStatus")
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
        }
    };

    //继电器模块
    Blockly.Blocks.microbit_relay = {
        init:function(){
        this.setColour(color_do);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/22.Relay-Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_RELAY)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P14', "pin14"],
            ['P15', "pin15"],
        ]),"relay")
        this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_STATUS)
        .appendField(new Blockly.FieldDropdown([
            [Blockly.Msg.MICROBIT_RELAYCLOSE, "True"],
            [Blockly.Msg.MICROBIT_RELAYOPEN, "False"],
            ]),"relayStatus")
        this.setPreviousStatement(true,null);
        this.setNextStatement(true,null);
        this.setTooltip('');
        }
    };

    //激光发射传感器
    Blockly.Blocks.microbit_laser = {
        init:function(){
        this.setColour(color_do);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/50-Laser Emission Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_LASER)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                ['P13', "pin13"],
                ['P14', "pin14"],
                ['P15', "pin15"],
            ]),"laser")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_STATUS)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_OPEN, "True"],
                [Blockly.Msg.MICROBIT_CLOSE, "False"],
            ]),"laserStatus")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };


    //红外接收模块
    Blockly.Blocks.microbit_irInit = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/18.IR  Receiver.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_IR)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P14', "pin14"],
            ['P15', "pin15"],
             ]),"irPort")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    //红外接收模块
    Blockly.Blocks.microbit_irLogic = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/18.IR  Receiver.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_IRLOGICVALUE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
    this.setTooltip('');
        }
    };

    //红外接收模块
    Blockly.Blocks.microbit_ir = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/18.IR  Receiver.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_IRRECEIVERDATA)
            .appendField(new Blockly.FieldDropdown([
            ['A', "0x45"],
            ['B', "0x46"],
            ['C', "0x47"],
            ['D', "0x44"],
            ['UP', "0x40"],
            ['+', "0x43"],
            ['LEFT', "0x07"],
            ['OK', "0x15"],
            ['RIGHT', "0x09"],
            ['0', "0x16"],
            ['DOWN', "0x19"],
            ['-', "0x0D"],
            ['1', "0x0C"],
            ['2', "0x18"],
            ['3', "0x5E"],
            ['4', "0x08"],
            ['5', "0x1C"],
            ['6', "0x5A"],
            ['7', "0x42"],
            ['8', "0x52"],
            ['9', "0x4A"],
        ]),"mappingValue")
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };

    //舵机
    Blockly.Blocks.microbit_servo = {
        init:function(){
            this.setColour(color_do);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/Servo.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_SERVO)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P3', "pin3"]
            ]),"servoPort")
                this.appendValueInput("servoAngle", Number)
                .appendField(Blockly.Msg.MICROBIT_SERVOANGLE)
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    

//======================传感器=========================
    //声音传感器
    Blockly.Blocks.microbit_vioce = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/29.Sound-Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_VIOCE)
            .appendField(Blockly.Msg.MICROBIT_DIGITALPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
            ]),"vioceDigital")
            .appendField(Blockly.Msg.MICROBIT_ANALOGPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
               
            ]),"vioceAnalog")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };


    //声音传感器模拟值
    Blockly.Blocks.microbit_vioceAnalog = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/29.Sound-Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_VIOCEANALOG)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
            ]),"vioceAnalog")
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

      //声音传感器数字值
      Blockly.Blocks.microbit_vioceDigital = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/29.Sound-Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_VIOCE)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                // ['P8', "pin8"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"vioceDigital")
            .appendField(Blockly.Msg.MICROBIT_VIOCEDIGITAL)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };


    //气体传感器
    Blockly.Blocks.microbit_gas = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/6.MQ  Gas  sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_GAS)
            .appendField(Blockly.Msg.MICROBIT_DIGITALPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P13', "pin13"],
                ['P15', "pin15"],
            ]),"gasDigital")
            .appendField(Blockly.Msg.MICROBIT_ANALOGPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P2', "pin2"],
                ['P12', "pin12"],
                ['P14', "pin14"],
                ['P16', "pin16"],
            ]),"gasAnalog")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };


    //气体传感器模拟值
    Blockly.Blocks.microbit_gasAnalog = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/6.MQ  Gas  sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_GAS)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P12', "pin12"],
                // ['P14', "pin14"],
                // ['P16', "pin16"],
            ]),"gasAnalog")
            .appendField(Blockly.Msg.MICROBIT_GASANALOG)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

      //气体传感器数字值
      Blockly.Blocks.microbit_gasDigital = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/6.MQ  Gas  sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_GAS)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                // ['P8', "pin8"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"gasDigital")
            .appendField(Blockly.Msg.MICROBIT_GASDIGITAL)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };





    //光敏传感器
    Blockly.Blocks.microbit_light = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/8.Photosensitive Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_LIGHT)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P8', "pin8"],
                // ['P12', "pin12"],
                // ['P13', "pin13"],
                // ['P14', "pin14"],
                // ['P15', "pin15"],
            ]),"microbitLight")
            .appendField(Blockly.Msg.MICROBIT_READLIGHT)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    //热敏传感器
    Blockly.Blocks.microbit_thermosensitive = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/28.Thermal  sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_THERMOSENSITIVE)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P8', "pin8"],
                // ['P12', "pin12"],
                // ['P13', "pin13"],
                // ['P14', "pin14"],
                // ['P15', "pin15"],
            ]),"thermosensitive")
            .appendField(Blockly.Msg.MICROBIT_THERMOSENSITIVEANALOG)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

//火焰传感器
    Blockly.Blocks.microbit_fire = {
        init:function(){
            this.setColour(color_sensor);
            this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/35.Flame-Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_FIRE)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P12', "pin12"],
                // ['P14', "pin14"],
                // ['P16', "pin16"],
            ]),"fireAnalog")
            .appendField(Blockly.Msg.MICROBIT_FIREANALOG)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
            this.setTooltip('');
        }
    };

    //火焰传感器读取数字值
    Blockly.Blocks.microbit_fireReadDigital = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/35.Flame-Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_FIRE)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                // ['P8', "pin8"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"fireDigital")
            .appendField(Blockly.Msg.MICROBIT_FIREDIGITAL)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };


    //温湿度传感器
    Blockly.Blocks.microbit_DHT11 = {
        init:function(){
            this.setColour(color_sensor);
            this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/12.Temperature   and humidity  sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_DHT11)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                ['P13', "pin13"],
                ['P14', "pin14"],
                ['P15', "pin15"],
            ]),"dht11Port")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_DHT11GET)
            .appendField(
            new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_TEMPERATURE, "temperature()"],
                [Blockly.Msg.MICROBIT_HUMIDITY, "humidity()"],
            ]),"dnt11Func")
            this.appendDummyInput("")
            // .appendField(Blockly.Msg.MICROBIT_ANALOG)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
            this.setTooltip('');
        }
    };



    //土壤湿度传感器
    Blockly.Blocks.microbit_soil = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/26.Soit moisture Module.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_SOIL)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P8', "pin8"],
                // ['P12', "pin12"],
                // ['P13', "pin13"],
                // ['P14', "pin14"],
                // ['P15', "pin15"],
            ]),"soil")
            .appendField(Blockly.Msg.MICROBIT_SOILANALOG)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    //雨滴传感器
    Blockly.Blocks.microbit_rain = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/30.Water  droplets Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_RAIN)
            .appendField(Blockly.Msg.MICROBIT_DIGITALPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"rainDigital")
            .appendField(Blockly.Msg.MICROBIT_ANALOGPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P14', "pin14"],
                // ['P16', "pin16"],
            ]),"rainAnalog")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

     //雨滴传感器模拟值
     Blockly.Blocks.microbit_rainAnalog = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/30.Water  droplets Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_RAIN)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P12', "pin12"],
                // ['P14', "pin14"],
                // ['P16', "pin16"],
            ]),"rainAnalog")
            .appendField(Blockly.Msg.MICROBIT_RAINANALOG)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

      //雨滴传感器数字值
      Blockly.Blocks.microbit_rainDigital = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/30.Water  droplets Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_RAIN)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"rainDigital")
            .appendField(Blockly.Msg.MICROBIT_RAINDIGITAL)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };



    //水深传感器
Blockly.Blocks.microbit_waterdeep = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/25.Water  depth  Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_WATERDEEP)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P8', "pin8"],
                // ['P12', "pin12"],
                // ['P13', "pin13"],
                // ['P14', "pin14"],
                // ['P15', "pin15"],
            ]),"waterdeep")
            .appendField(Blockly.Msg.MICROBIT_WATERDEEPANALOG)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    //人体热释电传感器
Blockly.Blocks.microbit_body = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/38.Human  Body-Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_BODY)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                ['P13', "pin13"],
                ['P14', "pin14"],
                ['P15', "pin15"],
            ]),"body")
            .appendField(Blockly.Msg.MICROBIT_READBODY)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
        this.setOutput(true, 'Boolean');
        this.setTooltip('');
        }
    };

    //循迹传感器
    Blockly.Blocks.microbit_track = {
        init:function(){
            this.setColour(color_sensor);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/9.Power.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_TRACK)
                .appendField(new Blockly.FieldDropdown([
                    ['P0', "pin0"],
                    ['P1', "pin1"],
                    ['P2', "pin2"],
                    ['P8', "pin8"],
                    ['P12', "pin12"],
                    ['P13', "pin13"],
                    ['P14', "pin14"],
                    ['P15', "pin15"],
                ]),"track")
                .appendField(Blockly.Msg.MICROBIT_READTRACK)
                this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };


//磁簧开关传感器是否检测到磁场
    Blockly.Blocks.microbit_reed_switch = {
        init:function(){
            this.setColour(color_sensor);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/5.Magnetic   Switch.svg", 84, 42))
                    .appendField(Blockly.Msg.MICROBIT_REEDSWITCH)
                    .appendField(new Blockly.FieldDropdown([
                        ['P0', "pin0"],
                        ['P1', "pin1"],
                        ['P2', "pin2"],
                        ['P8', "pin8"],
                        ['P12', "pin12"],
                        ['P13', "pin13"],
                        ['P14', "pin14"],
                        ['P15', "pin15"],
                    ]),"reedPort")
                    .appendField(Blockly.Msg.MICROBIT_ISREED)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };

    //灰度传感器读值
    Blockly.Blocks.microbit_grayscale = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/46-Grayscale Sensor.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_GRAYSCALE)
                .appendField(new Blockly.FieldDropdown([
                    ['P0', "pin0"],
                    ['P1', "pin1"],
                    ['P2', "pin2"],
                    // ['P8', "pin8"],
                    // ['P12', "pin12"],
                    // ['P13', "pin13"],
                    // ['P14', "pin14"],
                    // ['P15', "pin15"],
                ]),"grayscale")
                .appendField(Blockly.Msg.MICROBIT_GRAYSCALEANALOG)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    //震动传感器读值
    Blockly.Blocks.microbit_shock = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/47-Shock Sensor.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_SHOCK)
                .appendField(Blockly.Msg.MICROBIT_DIGITALPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                // ['P8', "pin8"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"shockDigital")
            .appendField(Blockly.Msg.MICROBIT_ANALOGPORT)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P12', "12"],
                // ['P14', "14"],
                // ['P16', "16"],
            ]),"shockAnalog")
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_SHOCKVALUE)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_DIGITAL, "1"],
                [Blockly.Msg.MICROBIT_ANALOG, "2"],
            ]),"shockValue")
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    //震动传感器模拟值
    Blockly.Blocks.microbit_shockAnalog = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/47-Shock Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_SHOCK)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P12', "pin12"],
                // ['P14', "pin14"],
                // ['P16', "pin16"],
            ]),"shockAnalog")
            .appendField(Blockly.Msg.MICROBIT_SHOCKANALOG)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

      //震动传感器数字值
      Blockly.Blocks.microbit_shockDigital = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/47-Shock Sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_SHOCK)
            .appendField(new Blockly.FieldDropdown([
                ['P1', "pin1"],
                ['P8', "pin8"],
                ['P12', "pin12"],
                // ['P8', "pin8"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"shockDigital")
            .appendField(Blockly.Msg.MICROBIT_SHOCKDIGITAL)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };

    

    //避障传感器数字值
    Blockly.Blocks.microbit_AvoidanceDigital = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/avoidance sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_AVOIDANCE)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P3', "pin3"],
                ['P4', "pin4"],
                ['P5', "pin5"],
                ['P6', "pin6"],
                ['P7', "pin7"],
                ['P8', "pin8"],
                ['P9', "pin9"],
                ['P10', "pin10"],
                ['P11', "pin11"],
                ['P12', "pin12"],
                ['P13', "pin13"],
                ['P14', "pin14"],
                ['P15', "pin15"],
                ['P16', "pin16"],
                ['P17', "pin17"],
                ['P18', "pin18"],
                ['P19', "pin19"],
                ['P20', "pin20"],
                // ['P8', "pin8"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"avoidanceDigital")
            .appendField(Blockly.Msg.MICROBIT_AVOIDANCEDIGITAL)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
            this.setOutput(true, 'Boolean');
            this.setTooltip('');
        }
    };

    //震动传感器模拟值
    Blockly.Blocks.microbit_AvoidanceAnalog = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/avoidance sensor.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_AVOIDANCE)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                ['P3', "pin3"],
                ['P4', "pin4"],
                ['P10', "pin10"],
                // ['P12', "pin12"],
                // ['P14', "pin14"],
                // ['P16', "pin16"],
            ]),"avoidanceAnalog")
            .appendField(Blockly.Msg.MICROBIT_AVOIDANCEANALOG)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

    //lm35温度传感器
    Blockly.Blocks.microbit_lm35 = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/3.LM35 Sensor.svg", 84, 42))
            // .appendField(Blockly.Msg.MICROBIT_SHOCK)
            .appendField(new Blockly.FieldDropdown([
                ['P0', "pin0"],
                ['P1', "pin1"],
                ['P2', "pin2"],
                // ['P8', "pin8"],
                // ['P13', "pin13"],
                // ['P15', "pin15"],
            ]),"lm35Pin")
            .appendField(Blockly.Msg.MICROBIT_LM35)
            this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
            this.setOutput(true, 'Number');
            this.setTooltip('');
        }
    };

    //倾斜传感器 是否倾斜
    Blockly.Blocks.microbit_tilt = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/48-Tilt Switch Sensor.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_TILT)
                .appendField(new Blockly.FieldDropdown([
                    ['P0', "pin0"],
                    ['P1', "pin1"],
                    ['P2', "pin2"],
                    ['P8', "pin8"],
                    ['P12', "pin12"],
                    ['P13', "pin13"],
                    ['P14', "pin14"],
                    ['P15', "pin15"],
                ]),"tilt")
                .appendField(Blockly.Msg.MICROBIT_ISTILT)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
        this.setOutput(true, 'Boolean');
        this.setTooltip('');
        }
    };

    //rgb超声波模块初始化
    Blockly.Blocks.microbit_rgbUltrasonicInit = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/52.RGB ultrasonic Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_ULTRASONICPIN)
        .appendField(Blockly.Msg.MICROBIT_IOPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
        ]),"ioPort")
        .appendField(Blockly.Msg.MICROBIT_RGBPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
        ]),"rgbPort")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    //RGB超神波传感器读取距离
    Blockly.Blocks.microbit_rgbUltrasonicDistance = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/52.RGB ultrasonic Module.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_RGBULTRASONICDISTANCE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

     //设置RGB超声波灯珠颜色
     Blockly.Blocks.microbit_rgbUltrasonicColor = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/52.RGB ultrasonic Module.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_RGBULTRASONICCOLOR)
                .appendField(new Blockly.FieldDropdown([
                    [Blockly.Msg.MICROBIT_RGBULTRASONICLEFT, "left"],
                    [Blockly.Msg.MICROBIT_RGBULTRASONICRIGHT, "right"],
                    [Blockly.Msg.MICROBIT_RGBULTRASONICTWO, "double"],
                ]),"rgbLight")
                .appendField(Blockly.Msg.MICROBIT_RGBULTRASONICSPECIAL)
                .appendField(new Blockly.FieldDropdown([
                    [Blockly.Msg.MICROBIT_RGBBREATHING, "breathing"],
                    [Blockly.Msg.MICROBIT_RGBROTATE, "rotate"],
                    [Blockly.Msg.MICROBIT_RGBFLICKER, "flicker"],
                ]),"rgbSpecial")
                this.appendValueInput("rgbBrightness", Number)
                .appendField(Blockly.Msg.MICROBIT_BRIGHTNESS)
                this.appendValueInput("COLOR", Number)
                .appendField(Blockly.Msg.MICROBIT_DISPLAYCOLOR)
                // this.appendValueInput("rgbUlr", Number)
                // .appendField(Blockly.Msg.MICROBIT_RGBR)
                // this.appendValueInput("rgbUlg", Number)
                // .appendField(Blockly.Msg.MICROBIT_RGBG)
                // this.appendValueInput("rgbUlb", Number)
                // .appendField(Blockly.Msg.MICROBIT_RGBB)            
                this.setPreviousStatement(true,null);
                this.setNextStatement(true,null);
                this.setTooltip('');
        }
    };

    //普通超声波模块初始化
    Blockly.Blocks.microbit_ultrasonicInit = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/40.ph_ultrasonic.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_ULTRASONICPININIT)
        .appendField(Blockly.Msg.MICROBIT_TRIGPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
        ]),"trigPort")
        .appendField(Blockly.Msg.MICROBIT_ECHOPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
        ]),"echoPort")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    //普通超神波传感器读取距离
    Blockly.Blocks.microbit_ultrasonicDistance = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/40.ph_ultrasonic.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_ULTRASONICDISTANCE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };


    return Blockly;
}

    

//twoStepperMotorAngle

module.exports = SensorbitUnoBlocks;
